// is mobile

function isMobile() {
  let flag =
    /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
      navigator.userAgent
    )
  return flag
}

function driveRoad(map, lat, lng, title) {
  // pc端规划路劲 移动端打开百度地图
  if (isMobile()) {
    window.location.href = `http://api.map.baidu.com/marker?location=${lat},${lng}&title=${title}&output=html`
  } else {
    const driving = new BMap.DrivingRoute(map, {
      renderOptions: {
        map: map,
        autoViewport: true,
      },
    })
    // 政府坐标
    const start = new BMap.Point(116.66728400036311, 40.15606203259834)
    const end = new BMap.Point(lng, lat)
    driving.search(start, end)
    window._driving_map = driving
  }
}

export { driveRoad }
